"use strict";
var url = require("url");
var fs = require("fs");

//把URL转换成路径资源
function url_to_path(url_str) {
    var url_obj = url.parse(url_str); // url信息封装成json对象
    return url_obj.path; //得到路径信息
}


module.exports = function static_res(parent_path) {
    return function (req, res, next) {
        var path = url_to_path(req.url);
        function callback(err, data) {
            if (err) {
                res.statusCode = 404;
                next();
            } else {
                res.write(data);
                res.end();
            }
        }
        fs.readFile(parent_path + path, callback);
    };
};